package com.itheima;


import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.*;
import javax.xml.soap.Text;
import java.util.Map;


public class MessageConsumer {

    public static void main(String[] args) throws Exception {
        //1.创建连接工厂ConnectionFactoty
        ActiveMQConnectionFactory connectionFactory= new ActiveMQConnectionFactory("tcp://192.168.144.100:61616");
        //2. 通过工厂获取连接Connection,并开启连接
        Connection connection = connectionFactory.createConnection();
        connection.start();
        //3.通过连接创建会话Seesion
        //参数一  false: 代表是否需要事务, 参数二 :代表应答机制
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        //4.创建目的地 Queue 和Topic  destination(目的地)
        Queue queue = session.createQueue("queue");

        Topic topic = session.createTopic("topic");

        //5.创建消息消费者
        javax.jms.MessageConsumer consumer = session.createConsumer(queue);

        //6.监听中间件获取消息
        consumer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                //将从监听中获取的数据转换为文本信息
               TextMessage textMessage= (TextMessage) message;
                try {
                    System.out.println(textMessage.toString());

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

    }
}
